package com.lineage.data.item_etcitem;

import com.lineage.config.ConfigClan;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.sql.ClanTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Clan;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.WorldClan;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class clan_glass extends ItemExecutor {
  private int a;
  
  private static final Log _log = LogFactory.getLog(clan_glass.class);
  
  public static ItemExecutor get() {
    return new clan_glass();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (pc.getClanid() == 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fY您尚未加入血盟无法使用"));
      return;
    } 
    if (pc.getQuest().get_step(8544) == 1) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("今日贡献能量已达上限"));
      return;
    } 
    if (!pc.getClanname().equals(pc.getClanNameContribution()))
      pc.setClanNameContribution(pc.getClanname()); 
    L1Clan clan = WorldClan.get().getClan(pc.getClanname());
    clan.setClanContribution(clan.getClanContribution() + this.a);
    ClanTable.getInstance().updateClan(clan);
    pc.setPcContribution(pc.getPcContribution() + this.a);
    pc.setClanContribution(pc.getClanContribution() + this.a);
    pc.getInventory().storeItem(92164, this.a);
    pc.sendPackets((ServerBasePacket)new S_SystemMessage("获得血盟贡献币:【" + this.a + "】个。"));
    pc.sendPackets((ServerBasePacket)new S_SystemMessage("你给予目前的血盟贡献度有【" + pc.getClanContribution() + "】点。"));
    pc.sendPackets((ServerBasePacket)new S_SystemMessage("你的血盟目前所获得的贡献度总合有【" + clan.getClanContribution() + "】点。"));
    pc.sendPackets(
        (ServerBasePacket)new S_SystemMessage("获得[" + pc.getPcContribution() + "/" + ConfigClan.PcContribution + "]点血盟能量值。"));
    pc.getInventory().removeItem(item, 1L);
    if (pc.getPcContribution() >= ConfigClan.PcContribution) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fY每日血盟能量上限:" + ConfigClan.PcContribution));
      pc.setPcContribution(ConfigClan.PcContribution);
      pc.getQuest().set_step(8544, 1);
      pc.setPcContribution(0);
    } 
  }
  
  public void set_set(String[] set) {
    this.a = Integer.parseInt(set[1]);
  }
}
